package com.common.impl;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.common.dao.BiotechDAO;
import com.common.model.Biotech;
import com.common.service.BiotechService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class BiotechServiceImpl implements BiotechService {
	private BiotechDAO biotechdao;
	

	@Override
	public List<Biotech> search(Biotech biotech) {
		return biotechdao.list( biotech);
	}
	
	@Override
	public List<Biotech> listrepair_(String repairman) {
		return biotechdao.listrepair(repairman);
	}
	
	@Override
	public void del(Biotech bio) {
		biotechdao.del(bio);
	}
	
	@Override
	public Biotech load(int id) {
		return biotechdao.load(id);
	}
	
	@Override
	public boolean pai(Biotech biotech) {
		return biotechdao.pai(biotech);
	}
	
	//查看报修记录
	@Override
	public String loadAllJson0(String author) {
		List<Biotech> list = biotechdao.list0(author);
		if(list.size()>0){
			JSONArray jsonarr = JSONArray.fromObject(list);
			return jsonarr.toString();
		}else{
			return null;
		}
	}
	
	@Override
	public boolean save(Biotech biotech) {
		biotech.setPubdate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		return biotechdao.save(biotech);
	}
	
	@Override
	public List<Biotech> listrepair0(Biotech biotech) {
		return biotechdao.listrepair0(biotech);
	}
	
	@Override
	public List<Biotech> listrepair1(String repairman) {
		return biotechdao.listrepair1(repairman);
	}
	
	@Override
	public boolean updatestatus(int status, Biotech biotech) {
		return biotechdao.updatestatus(status, biotech);
	}
	
	@Override
	public String listrepair(String repairman) {
		List<Biotech> list = biotechdao.listrepair(repairman);
		if(list.size()>0){
			JSONArray jsonarr = JSONArray.fromObject(list);
			return jsonarr.toString();
		}else{
			return null;
		}
	}
	
	@Override
	public String detail(int goodsId) {
		return null;
	}

	@Override
	public String list() {
		return null;
	}
	
	@Override
	public String loadAllJson() {
		return null;
	}

	@Override
	public String detailjson(String id) {
		Integer goodid= Integer.parseInt(id);
		Biotech good = this.load(goodid);
		if(good != null){
			JSONObject obj = JSONObject.fromObject(good);
			return obj.toString();
		}else{
			return null;
		}
		
	}

	@Override
	public String loadAllJson2(Biotech biotech) {
		List<Biotech> list = biotechdao.list(biotech);
		if(list.size()>0){
			JSONArray jsonarr = JSONArray.fromObject(list);
			return jsonarr.toString();
		}else{
			return null;
		}
	}
	
	@Override
	public List<Biotech> listbiotech() {
		return biotechdao.list(null);
	}

	public BiotechDAO getBiotechdao() {
		return biotechdao;
	}

	public void setBiotechdao(BiotechDAO biotechdao) {
		this.biotechdao = biotechdao;
	}
	
	@Override
	public boolean shenhe(Biotech biotech) {
		return biotechdao.shenhe(biotech);
	}

	@Override
	public String list3() {
		List<Biotech> list = biotechdao.list3();
		if(list.size()>0){
			JSONArray jsonarr = JSONArray.fromObject(list);
			return jsonarr.toString();
		}else{
			return null;
		}
	}
	
	public List<Biotech> loadAllJson0_(String author) {
		return biotechdao.list0(author);
	}

	@Override
	public List<Biotech> yixiu(String author) {
		return biotechdao.yixiu(author);
	}
	
	

}
